package edu.scdx.controller;
import java.util.List;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import edu.scdx.common.util.JsonUtil;
import edu.scdx.entity.User;
import edu.scdx.entity.UserInfo;
import edu.scdx.service.UserInfoService;
import edu.scdx.service.UserService;

@Controller
@RequestMapping("/userInfo")
public class UserInfoController {
	
	@Autowired
    private UserInfoService userInfoService;

	public UserInfoService getUserInfoService() {
		return userInfoService;
	}

	public void setUserInfoService(UserInfoService userInfoService) {
	
		this.userInfoService = userInfoService;
	}
	
	@RequestMapping("/seeInfo.do")
    public String getInfo(Model model,HttpSession session){	
		
		String userTel=(String) session.getAttribute("userTel");
		
		UserInfo userInfo=userInfoService.getUserInfo(userTel);
		
		model.addAttribute("user",userInfo);
		
    	return "userInfo";
    }
	
	@RequestMapping("/change.do")
    public String change(Model model,HttpSession session){	
								
    	return "changeInfo";
    
	}
	
	@RequestMapping("/changeInfo.do")
    public String changeInfo(Model model,HttpSession session,String userName,String userSex,String userBirthday){	
				
		String userTel=(String) session.getAttribute("userTel");
		
		userInfoService.updateUserInfo(userTel,userName,userSex,userBirthday);
		
				
    	return "changeUserInfoSucceed";
    
	}
	
	@RequestMapping("/toAddMoney.do")
    public String addMondy(Model model,HttpSession session,String userName,String userSex,String userBirthday){	
								
    	return "addMoney";
    
	}
	
	@RequestMapping("/addMoney.do")
    public String changeInfo(Model model,HttpSession session,int userMoney){	
				
		String userTel=(String) session.getAttribute("userTel");
		
		
		userInfoService.updateUserMoney(userTel,userMoney);
		
				
    	return "addMoneySucceed";
    
	}
	
	@RequestMapping("/lingquan.do")
    public String linguan(Model model,HttpSession session){	
				
	
    	return "lingquan";
    
	}
	
	

}
